package elephant.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

/**
 * 
 * @author icecooly
 *
 */
public class DumpUtil {
	private DumpUtil(){}
	/*dump invoke parameter*/
	public static String dumpParameter(String callToken,Object []args){
		return dumpParameter(callToken, args,0);
	}
	/**
	 * @param callToken String
	 * @param args Object[]
	 * @return String
	 */
	public static String dumpParameter(String callToken,Object []args,int startIndex){
		StringBuilder sb=new StringBuilder();
		sb.append("\n--------------------------------------------------------\n");
		sb.append("InvokeMethod:"+callToken+"\n");
		if(args!=null){
			for(int i=startIndex;i<args.length;i++){
				sb.append("args["+i+"]:"+
						JSON.toJSONString(args[i],SerializerFeature.PrettyFormat)+"\n");
			}
		}
		sb.append("--------------------------------------------------------\n");
		return sb.toString();
	} 
	/*dump invoke parameter*/
	/**
	 * @param callToken String
	 * @param o Object
	 * @return String
	 */
	public static String dumpObject(String callToken,Object o){
		StringBuilder sb=new StringBuilder();
		sb.append("\n--------------------------------------------------------\n");
		sb.append("InvokeMethod:"+callToken+" ret\n");
		if(o==null){
			sb.append("<NULL>\n");
		}else{
			sb.append(JSON.toJSONString(o,SerializerFeature.PrettyFormat)+"\n");
		}
		sb.append("--------------------------------------------------------\n");
		return sb.toString();
	}
	//
	public static String dump(Object o){
		if(o==null){
			return "<NULL>";
		}
		return JSON.toJSONString(o,SerializerFeature.PrettyFormat);
	}
}
